package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.base.BaseModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.ShareFaceToFaceContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;
import javax.inject.Inject;

import rx.Subscriber;

/**
 * Created by Jiangzx on 2017/8/18 18:15.
 */

public class ShareFaceToFacePresenter extends BasePresenter implements ShareFaceToFaceContract.Presenter {
    @Inject
    Context context;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil jsonUtil;

    private ShareFaceToFaceContract.View view;
    @Inject
    public ShareFaceToFacePresenter(ShareFaceToFaceContract.View view){
        this.view=view;
    }

    @Override
    public void getShareDes() {
        view.showLoadingDialog(context.getString(R.string.loading));
        ApiServiceHelper.
                appointThreadNormal(apiService.getShareDes(jsonUtil.getRsaParams())).
                subscribe(new Subscriber<BaseModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.closeLoadingDialog();
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(BaseModel baseModel) {
                        view.setShareDes((String) baseModel.getData());
                    }
                });
    }
}
